package me.minecraft.mod.cobblemonbukkitevent.bukkit;

import com.cobblemon.mod.common.api.battles.model.PokemonBattle;
import com.cobblemon.mod.common.api.battles.model.actor.BattleActor;
import com.cobblemon.mod.common.api.moves.MoveTemplate;
import com.cobblemon.mod.common.battles.pokemon.BattlePokemon;
import com.cobblemon.mod.common.item.battle.BagItem;
import me.minecraft.mod.cobblemonbukkitevent.bukkit.event.*;
import org.bukkit.Bukkit;

/**
 * Bukkit事件工厂类，用于创建和调用事件
 * @author langle__
 * @version 1.0
 */
public class EventFactory {

    /**
     * 调用物品使用事件
     * @param battle 对战实例
     * @param target 目标宝可梦
     * @param item 使用的物品
     * @param after 是否为使用后事件
     * @return 调用后的事件实例
     */
    public static ItemUsedEvent callItemUsedEvent(PokemonBattle battle, BattlePokemon target, BagItem item, boolean after) {
        ItemUsedEvent event = new ItemUsedEvent(battle, target, item, after);
        Bukkit.getPluginManager().callEvent(event);
        return event;
    }

    /**
     * 调用技能选择事件
     * @param battle 对战实例
     * @param userPokemon 使用技能的宝可梦
     * @param targetPokemon 目标宝可梦
     * @param move 技能模板
     * @return 调用后的事件实例
     */
    public static MoveSelectedEvent callMoveSelectedEvent(PokemonBattle battle, BattlePokemon userPokemon, BattlePokemon targetPokemon, MoveTemplate move) {
        MoveSelectedEvent event = new MoveSelectedEvent(battle, userPokemon, targetPokemon, move);
        Bukkit.getPluginManager().callEvent(event);
        return event;
    }

    /**
     * 调用技能使用事件
     * @param battle 对战实例
     * @param user 使用技能的宝可梦
     * @param target 目标宝可梦
     * @param move 技能模板
     * @return 调用后的事件实例
     */
    public static MoveUsedEvent callMoveUsedEvent(PokemonBattle battle, BattlePokemon user, BattlePokemon target, MoveTemplate move) {
        MoveUsedEvent event = new MoveUsedEvent(battle, user, target, move);
        Bukkit.getPluginManager().callEvent(event);
        return event;
    }

    /**
     * 调用战斗放弃事件
     * @param battle 对战实例
     * @param forfeitingActor 放弃对战的参与者
     * @param forfeitingPokemon 放弃对战的宝可梦
     * @param before 是否为放弃前事件
     * @return 调用后的事件实例
     */
    public static BattleForfeitEvent callBattleForfeitEvent(PokemonBattle battle, BattleActor forfeitingActor, BattlePokemon forfeitingPokemon, boolean before) {
        BattleForfeitEvent event = new BattleForfeitEvent(battle, forfeitingActor, forfeitingPokemon, before);
        Bukkit.getPluginManager().callEvent(event);
        return event;
    }

    /**
     * 调用宝可梦切换开始事件
     * @param battle 对战实例
     * @param actor 参与者
     * @param oldPokemon 原宝可梦
     * @param newPokemon 新宝可梦
     * @return 调用后的事件实例
     */
    public static PokemonSwitchStartEvent callPokemonSwitchStartEvent(PokemonBattle battle, BattleActor actor, BattlePokemon oldPokemon, BattlePokemon newPokemon) {
        PokemonSwitchStartEvent event = new PokemonSwitchStartEvent(battle, actor, oldPokemon, newPokemon);
        Bukkit.getPluginManager().callEvent(event);
        return event;
    }

    /**
     * 调用宝可梦切换结束事件
     * @param battle 对战实例
     * @param actor 参与者
     * @param oldPokemon 原宝可梦
     * @param newPokemon 新宝可梦
     * @return 调用后的事件实例
     */
    public static PokemonSwitchEndEvent callPokemonSwitchEndEvent(PokemonBattle battle, BattleActor actor, BattlePokemon oldPokemon, BattlePokemon newPokemon) {
        PokemonSwitchEndEvent event = new PokemonSwitchEndEvent(battle, actor, oldPokemon, newPokemon);
        Bukkit.getPluginManager().callEvent(event);
        return event;
    }

    /**
     * 调用战斗回合更新事件
     * @param battle 对战实例
     * @param turnNumber 回合数
     * @return 调用后的事件实例
     */
    public static BattleTurnUpdateEvent callBattleTurnUpdateEvent(PokemonBattle battle, int turnNumber) {
        BattleTurnUpdateEvent event = new BattleTurnUpdateEvent(battle, turnNumber);
        Bukkit.getPluginManager().callEvent(event);
        return event;
    }

}
